export default class WebsocketUtil {
  constructor(wsUrl) {
    this.wsUrl = wsUrl;
    this.ws = {};
  }
  //初始化连接
  initConn(openCallback, resCallback) {
    this.ws = new WebSocket(this.wsUrl);
    this.ws.onopen = () => {
      openCallback();
    };
    this.ws.onmessage = res => {
      resCallback(res);
    };
  }
  //发送数据
  send(stringData) {
    this.ws.send(stringData);
  }
  //关闭连接
  close() {
    this.ws.close();
  }
}
